# -*- coding: gbk -*-

"""
Miscs
"""

import signal, sys, logging, logging.handlers
import hall

def buildHeaderDict (header):
    output = {}
    for key, value in header:
        output[key.upper()] = value
    return output

def buildTagDict (tagList):
    output = {}
    for tag in tagList:
        output[tag] = True
    return output

def safeExit (signum, frame):
    print 'Exiting......'
    raise KeyboardInterrupt, None

def initSignal ():
    signal.signal(signal.SIGPIPE, signal.SIG_IGN)
    signal.signal(signal.SIGINT, safeExit)
    signal.signal(signal.SIGTERM, safeExit)


def setLogging (logFile, level = logging.INFO):
    logging.basicConfig (level = logging.DEBUG, format = hall.LOG_FORMAT)
    fileLog = logging.handlers.RotatingFileHandler (
        hall.LOG_PATH + '/' + logFile, maxBytes = 1024 * 1024 * 256)
    fileLog.setFormatter(logging.Formatter(hall.LOG_FORMAT))
    logging.getLogger('').addHandler (fileLog)
    return True

